// const http = require('http')

// const server = http.createServer()

// server.on('request', (req) => {
//   console.log(req, req.url, req.method);
// })

// server.listen(81, () => {
//   console.log("server running http://127.0.0.81")
// })

let http = require('http');
// 创建一个server服务器
let server = http.createServer((req, res)=>{

  // 返回的状态码
  // res.statusCode = 200;
  // res.setHeader("Content-Type", "text/plain; charset=utf-8");
  // 响应结束
  // res.end("Hello Node.js");
  // 链式调用，监听之后回调
}).on('request', (req, res) => {
  console.log(req.url);
  console.log(req.method);
  // console.log('成功访问!!!');
  res.setHeader('Content-Type', 'text/html; charset=utf-8');
  res.end("地址为: " + req.url + " 请求方式: " + req.method);
}).listen(3000, ()=>{
  console.log("服务器已经运行，打开浏览器，输入http://127.0.0.1/3000/进行访问");
});

